package com.example.config;

import com.example.beans.ShoppingCart;
import com.example.service.StoreService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.context.WebApplicationContext;

public class WebAppConfig {

    @Bean
    public StoreService storeService(ShoppingCart shoppingCart){
        StoreService storeService = new StoreService();
        storeService.setShoppingCart(shoppingCart);
        return storeService;
    }

    @Bean
    @Scope(value = WebApplicationContext.SCOPE_SESSION,
           proxyMode = ScopedProxyMode.TARGET_CLASS)
    public ShoppingCart shoppingCart(){
        return new ShoppingCart();
    }
}
